/**
 * RowHeaderRenderer.java
 */
package com.pluginsacceptor.plugin.spreadsheet.table;

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.table.JTableHeader;

/**
 * Create header row for table
 */
public class RowHeaderRenderer extends JLabel implements ListCellRenderer {

    /**
     * Constructor
     * @param table the source table
     */
    public RowHeaderRenderer(final JTable table) {
        final JTableHeader header = table.getTableHeader();
        setOpaque(true);
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
        setHorizontalAlignment(CENTER);
        setForeground(header.getForeground());
        setBackground(header.getBackground());
        setFont(header.getFont());
    }

    @Override
    public Component getListCellRendererComponent(
        final JList list,
        final Object value,
        final int index,
        final boolean isSelected,
        final boolean cellHasFocus
    ) {
        setText((value == null) ? "" : value.toString());
        return this;
    }
}

